//
//  RCMainViewController.swift
//  RCWeibo
//
//  Created by CL on 15/12/13.
//  Copyright © 2015年 CL. All rights reserved.
//

import UIKit

class RCMainViewController: UITabBarController {
    
    let mainTabBar = RCMainTabBar()
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //由于要自定义tabbar来添加中间加号按钮，所以来用  kvc
        setValue(mainTabBar, forKey: "tabBar")
        
        addChildViewControllers()
        
        //添加compose按钮的监听事件
        mainTabBar.composeBtn.addTarget(self, action: "composeBtnDidClick" , forControlEvents: .TouchUpInside)
    }

    //MARK:compose点击事件
    //这里的target方法添加了 pricate 后，要加objc
   @objc private func composeBtnDidClick(){
    
        print(__FUNCTION__)
    }
    //MARK:添加子视图控制器
    private func addChildViewControllers() {
        
        //设置tabbar的tintcolor
//        tabBar.tintColor = themeColor
        
        //添加子vc
        addChildViewController(RCHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(RCMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(RCDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(RCProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    
    private func addChildViewController(childController: UIViewController ,title: String ,imageName: String) {
        
        //        添加homeVC
        //        let homeVC = RCHomeTableViewController()
        
        //添加nav控制器
        let nav = UINavigationController(rootViewController: childController)
        
        childController.title = title
        
        //将nav添加到tabbarVC的子视图中
        addChildViewController(nav)
        //设置tabbaritem图片
        childController.tabBarItem.image = UIImage(named: imageName)
        
    }
    
    
    
}